package com.example.ppapp.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.example.ppapp.R;
import com.example.ppapp.adapter.ItemShopListViewAdapter;
import com.example.ppapp.domain.InfoBean;
import com.example.ppapp.utils.ContentDatas;

import java.util.ArrayList;
import java.util.List;

public class ShopActivity  extends AppCompatActivity implements View.OnClickListener {
    private List<InfoBean> infoBeans;
    private ListView listView;
    private TextView tv_title;
    private ItemShopListViewAdapter adapter;
    private int id;
    private String title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop);

        Intent intent = getIntent();
        id = intent.getIntExtra("id", 0);
        title = intent.getStringExtra("title");
        initView();
    }

    private void initView() {
        listView = findViewById(R.id.listView);
        tv_title = findViewById(R.id.tv_title);
        findViewById(R.id.img_car).setOnClickListener(this);
        findViewById(R.id.img_back).setOnClickListener(this);

        infoBeans = ContentDatas.getAllList().get(id);
        adapter = new ItemShopListViewAdapter(this, infoBeans);
        listView.setAdapter(adapter);
        tv_title.setText(title);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.img_back:
                onBackPressed();
                finish();
                break;
            case R.id.img_car:
                ArrayList<Integer> list = adapter.getList();
                startActivity(new Intent(this, ShoppingCarActivity.class).putIntegerArrayListExtra("list", list).putExtra("id", id));
                break;
        }
    }
}